package jdbc.util;

import jdbc.DBUtil;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Test {
    //查看班级编号为1的学生的id,name,job,age
    public static void main(String[] args) {
        try (
                Connection connection= DBUtil.getConnection();
        ){
            Statement statement=connection.createStatement();
            String sql="SELECT id,name,job,age "+
                       "FROM student "+
                       "WHERE class_id=1";
            ResultSet rs=statement.executeQuery(sql);
            while (rs.next()){
                int id=rs.getInt("id");
                String name=rs.getString("name");
                String job=rs.getString("job");
                int age=rs.getInt("age");
                System.out.println(id+","+name+","+job+","+age);
            }
        }catch (SQLException e){
            e.printStackTrace();
        }
    }
}
